package com.charging.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.charging.common.annotation.Log;
import com.charging.common.core.controller.BaseController;
import com.charging.common.core.domain.AjaxResult;
import com.charging.common.enums.BusinessType;
import com.charging.system.domain.KxArea;
import com.charging.system.service.IKxAreaService;
import com.charging.common.utils.poi.ExcelUtil;
import com.charging.common.core.page.TableDataInfo;

/**
 * 站点信息Controller
 *
 * @author charging
 * @date 2024-04-19
 */
@RestController
@RequestMapping("/system/area")
public class KxAreaController extends BaseController
{
    @Autowired
    private IKxAreaService kxAreaService;

    /**
     * 查询站点信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:area:list')")
    @GetMapping("/list")
    public TableDataInfo list(KxArea kxArea)
    {
        startPage();
        List<KxArea> list = kxAreaService.selectKxAreaList(kxArea);
        return getDataTable(list);
    }

    /**
     * 导出站点信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:area:export')")
    @Log(title = "站点信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KxArea kxArea)
    {
        List<KxArea> list = kxAreaService.selectKxAreaList(kxArea);
        ExcelUtil<KxArea> util = new ExcelUtil<KxArea>(KxArea.class);
        util.exportExcel(response, list, "站点信息数据");
    }

    /**
     * 获取站点信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:area:query')")
    @GetMapping(value = "/{areaId}")
    public AjaxResult getInfo(@PathVariable("areaId") Long areaId)
    {
        return success(kxAreaService.selectKxAreaByAreaId(areaId));
    }

    /**
     * 新增站点信息
     */
    @PreAuthorize("@ss.hasPermi('system:area:add')")
    @Log(title = "站点信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KxArea kxArea)
    {
        return toAjax(kxAreaService.insertKxArea(kxArea));
    }

    /**
     * 修改站点信息
     */
    @PreAuthorize("@ss.hasPermi('system:area:edit')")
    @Log(title = "站点信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KxArea kxArea)
    {
        return toAjax(kxAreaService.updateKxArea(kxArea));
    }

    /**
     * 删除站点信息
     */
    @PreAuthorize("@ss.hasPermi('system:area:remove')")
    @Log(title = "站点信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{areaIds}")
    public AjaxResult remove(@PathVariable Long[] areaIds)
    {
        return toAjax(kxAreaService.deleteKxAreaByAreaIds(areaIds));
    }
}
